package com.lzxuni.modules.disease.controller;


import com.alibaba.fastjson.JSON;
import com.lzxuni.common.utils.R;
import com.lzxuni.modules.disease.entity.DiseaseInformation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import com.lzxuni.modules.common.entity.PageParameter;
import com.lzxuni.modules.common.entity.PageData;
import com.lzxuni.common.utils.StringUtils;
import com.lzxuni.modules.disease.service.DiseaseInformationService;
import org.springframework.web.bind.annotation.RestController;
import com.lzxuni.modules.common.controller.BaseController;
import org.springframework.web.servlet.ModelAndView;

/**
 * <p>
 * 病情管理--病情详情 前端控制器
 * </p>
 *
 * @author gyl
 * @since 2020-12-02
 */
@RestController
@RequestMapping("/Disease/information")
public class DiseaseInformationController extends BaseController {

    @Autowired
    private DiseaseInformationService diseaseInformationService;
    private String templatesPath="/Disease/information";

    //主页面
    @RequestMapping("/Index")
    public ModelAndView Index() {
        ModelAndView mv = new ModelAndView(templatesPath+"/index");
        return mv;
    }

    //查询数据
    @RequestMapping("/GetList")
    public Object GetList(String pagination,String queryJson){
        PageParameter pageParameter = JSON.parseObject(pagination, PageParameter.class);
        DiseaseInformation diseaseInformation = JSON.parseObject(queryJson, DiseaseInformation.class);
        PageData pageData = getPageData(diseaseInformationService.queryPage(pageParameter, diseaseInformation));
        return R.ok().put("data", pageData);
    }

    //表单页
    @RequestMapping("/Form")
    public ModelAndView Form() {
        ModelAndView mv = new ModelAndView(templatesPath+"/form");
        return mv;
    }

    //删除数据
    @RequestMapping("/DeleteForm")
    public Object delete(String keyValue) {
        diseaseInformationService.removeById(keyValue);
        return R.ok("删除成功");
    }

    //保存数据
    @RequestMapping("/SaveForm")
    public Object insertDo(String keyValue,DiseaseInformation diseaseInformation) {
        diseaseInformation.setInformationId(keyValue);
        if(StringUtils.isEmpty(diseaseInformation.getInformationId())){
             diseaseInformationService.save(diseaseInformation);
             return R.ok("保存成功");
        }else{
            diseaseInformationService.updateById(diseaseInformation);
            return R.ok("修改成功");
        }
    }


}

